#ifndef SOCKET_H
#define SOCKET_H
#include <stdint.h>
#include <windows.h>
#include "mutex.h"
namespace RemoteObj
{
class Socket
{
public:

    virtual ~Socket();
    virtual int32_t open();
    virtual int32_t close();
    virtual int32_t read(void * buffer, int32_t length);
    virtual int32_t write(const void* buffer, int32_t length);
    virtual bool is_open() const;
    virtual bool peek() const;
    int32_t set_timeout(int32_t seconds, int32_t optname);
    int32_t set_send_timeout(int32_t seconds);
    int32_t set_recv_timeout(int32_t second);

    SOCKET get_socket() const
    {
        return _socket;
    }
protected:
    /**禁止直接使用*/
    Socket();
    /**系统SOCKET*/
    SOCKET _socket;
    int32_t _send_timeout;
    int32_t _recv_timeout;

protected:
    int32_t init();
    int32_t uninit();

private:
    /**
      控制只初始化一次
      Windows加载DLL
    */
    static int32_t _nofSockets;
    static Mutex _mutex;
};

}

#endif // SOCKET_H
